home *** CD-ROM | disk | FTP | other *** search
/ The Best of MacTutor - S…e Code for Volumes 1 to 5 / The Best of MacTutor - Source Code for Volume 1-5 (Wayzata Technology)(6031)(1990).bin / Source Code / #18 (Mar 87) / Printer LSP sources / PrintTest Main.TXT < prev    next >
Text File  |  1987-02-13  |  5KB  |  229 lines

  1. PROGRAM PrintTest;
  2.  
  3. {$I-}
  4.  
  5. { Examine and display TPrint record values.}
  6. { Written by Joel West , Western Software Technology}
  7. { LS Pascal source conversion by D. Smith }
  8.  
  9. {Begun with an underlying skeleton , using part of }
  10. {an example from Apple User Education}
  11. {File : Example code for a text editor by Cary Clark , }
  12. {Macintosh Technical Support Version 1.1 May 13 , 1985 }
  13.  
  14. {Portions copyright © 1986 by}
  15. { Joel West , Western Software Technology,}
  16. { for MacTutor. }
  17.  
  18.  
  19. {     A document in this program (built using TextEdit) is used to}
  20. {    display the contents of a modified TPrint record.}
  21. {    There are Job and Style dialogs for modifying the record, and}
  22. {    for actually printing out the document.}
  23.  
  24.  
  25.  
  26.     USES
  27.         MacPrint, MyGlobals, StringFormat, DumpTPrint, Windows, Printing, SetupMenus;
  28.  
  29.  
  30. {------------Alert for About…------------------}
  31.     PROCEDURE AboutThisProgram;
  32.         VAR
  33.             itemhit : INTEGER;
  34.             hand : StringHandle;
  35.     BEGIN
  36.         DialogueDeactivate;
  37.         hand := GetString(STR_id);
  38.         ParamText(hand^^, '', '', '');
  39.         itemhit := NoteAlert(ALRT_about, NIL);
  40.     END; {AboutThisProgram}
  41.  
  42. {---------------Handle menu command------------}
  43.     PROCEDURE DoCommand (commandkey : BOOLEAN);
  44.         VAR
  45.             daname : Str255;
  46.             refnum, theMenu, theItem : INTEGER;
  47.             menuResult : LONGINT;
  48.             daedit : BOOLEAN;
  49.     BEGIN
  50.         IF commandkey THEN
  51.             menuResult := MenuKey(theChar)
  52.         ELSE
  53.             menuResult := MenuSelect(myEvent.where);
  54.         theMenu := HiWord(menuResult);
  55.         theItem := LoWord(menuResult);
  56.         CASE theMenu OF
  57.             appleMenu : 
  58.                 BEGIN
  59.                     IF theItem = 1 THEN
  60.                         AboutThisProgram
  61.                     ELSE
  62.                         BEGIN
  63.                             GetItem(myMenus[appleMenu], theItem, daname);
  64.                             refNum := OpenDeskAcc(daname)
  65.                         END
  66.                 END;
  67.             fileMenu : 
  68.                 BEGIN
  69.                     CASE theItem OF
  70.                         newItem :            {New }
  71.                             OpenAWindow;
  72.                         closeItem :                  {Close }
  73.                             CloseAWindow;
  74.                         stlItem :            {PrStlDialog… }
  75.                             BEGIN
  76.                                 PrOpen;
  77.                                 DialogueDeactivate;
  78.                                 IF PrStlDialog(wdh^^.theTHP) THEN
  79.                                     DumpPrint('After PrintStlDialog(…)', wdh^^.theTHP);
  80.                                 PrClose
  81.                             END;
  82.                         jobItem :            {PrJobDialog… }
  83.                             BEGIN    { just modifying TPrint, not actually printing }
  84.                                 PrOpen;
  85.                                 DialogueDeactivate;
  86.                                 IF PrJobDialog(wdh^^.theTHP) THEN
  87.                                     DumpPrint('After PrJobDialog(…)', wdh^^.theTHP);
  88.                                 PrClose
  89.                             END;
  90.                         setupItem :            {Page Setup… }
  91.                             BEGIN
  92.                                 PrOpen;
  93.                                 DialogueDeactivate;
  94.                                 IF PrStlDialog(PrintHdl) THEN
  95.                                     BEGIN
  96.                                     END;
  97.                                 PrClose
  98.                             END;
  99.                         printItem :            {Print }
  100.                             printFlag := TRUE;    {Do it after segs unloaded}
  101.                         quitItem :            {Quit }
  102.                             doneFlag := TRUE;
  103.                         OTHERWISE    {required for LSP!}
  104.                             BEGIN
  105.                             END;
  106.                     END {CASE theItem}
  107.                 END; {fileMenu}
  108.             editMenu : 
  109.                 daedit := SystemEdit(theitem - 1);
  110.             OTHERWISE
  111.                 BEGIN
  112.                 END;
  113.         END; {CASE theMenu}
  114.  
  115.         HiLiteMenu(0);
  116.     END;  {DoCommand}
  117.  
  118. {---------------The main event loop--------------}
  119.     PROCEDURE MainEventLoop;
  120.         VAR
  121.             tempwindow : WindowPtr; {the find window}
  122.     BEGIN
  123.         REPEAT
  124.             SystemTask;
  125.             IF printFlag THEN
  126.                 BEGIN
  127.                     PrOpen;
  128.                     DoPrinting;
  129.                     PrClose
  130.                 END;
  131.             IF GetNextEvent(everyEvent, myEvent) THEN
  132.                 BEGIN
  133.                     CASE myEvent.what OF
  134.                         mouseDown : 
  135.                             BEGIN
  136.                                 CASE FindWindow(myEvent.where, tempwindow) OF
  137.                                     inMenuBar : 
  138.                                         DoCommand(FALSE);
  139.                                     inSysWindow : 
  140.                                         SystemClick(myEvent, tempwindow);
  141.                                     inDrag : 
  142.                                         DragWindow(tempwindow, myEvent.where, dragRect);
  143.                                     inContent : 
  144.                                         SysBeep(1);
  145.                                     inGoAway : 
  146.                                         IF TrackGoAway(tempwindow, myEvent.where) THEN
  147.                                             CloseAWindow;
  148.                                     OTHERWISE
  149.                                         BEGIN
  150.                                         END;
  151.                                 END {CASE FindWindow }
  152.                             END; {of mouseDown }
  153.                         keyDown, autoKey : 
  154.                             BEGIN
  155.                                 theChar := CHR(BitAnd(myEvent.message, charCodeMask));
  156.                                 IF BitAnd(myEvent.modifiers, CmdKey) <> 0 THEN
  157.                                     DoCommand(TRUE)    { do menu equivalent }
  158.                                 ELSE
  159.                                     SysBeep(1);        { no typing allowed! }
  160.                             END; {of keyDown}
  161.                         activateEvt : 
  162.                             MyActivate;
  163.                         updateEvt : 
  164.                             DrawWindow;
  165.                         OTHERWISE
  166.                             BEGIN
  167.                             END;
  168.                     END; {CASE Event.what }
  169.                     CheckWindowMode;
  170.                 END    {of true GetNextEvent}
  171.             ELSE IF (myEvent.what = nullEvent) AND doneFlag AND (FrontWindow <> NIL) THEN
  172.                 CloseAWindow;
  173. { We like to leave lots of memory available, so unload everything as a precaution }
  174.             UnloadSeg(@SWrite);            {segment StringFormat}
  175.             UnloadSeg(@PrintLine);        {segment DumpTPrint}
  176.             UnloadSeg(@OpenAWindow);    {segment Windows}
  177.             UnloadSeg(@DoPrinting);        {segment Printing}
  178.  
  179.         UNTIL doneFlag AND (FrontWindow = NIL);
  180.     END;
  181.  
  182. {-------- crash recovery ---------------}
  183.  
  184.     PROCEDURE crash;
  185.     BEGIN
  186.         ExitToShell;
  187.     END;
  188.  
  189. {-------------Memory initialization & Setup ---------}
  190.     PROCEDURE SetUpMemory;
  191.     BEGIN
  192.         InitGraf(@thePort);
  193.         InitFonts;
  194.         InitWindows;
  195.         InitMenus;
  196.         TEInit;
  197.         InitDialogs(@crash);
  198.         InitCursor;
  199.         MaxApplZone;
  200.         MoreMasters;
  201.         MoreMasters;
  202.         MoreMasters;
  203.         MoreMasters;
  204.  
  205.         FlushEvents(everyEvent, 0);
  206.  
  207.         watchHdl := GetCursor(WatchCursor);
  208.         HNoPurge(Handle(watchHdl));
  209.  
  210.         printHdl := THPrint(NewHandle(SizeOf(TPrint)));
  211.         PrOpen;
  212.         PrintDefault(printHdl);    { the one used for actual printing }
  213.         PrClose;
  214.  
  215.         Linebuff := '';    {required for LSP}
  216.  
  217.     END;
  218.  
  219.  
  220. {-------------Main program-------------}
  221.  
  222. BEGIN {main program }
  223.     SetUpMemory;
  224.     SetUpMenus;
  225.     SetUpWindow;
  226.     unloadseg(@SetUpMenus);
  227.     MainEventLoop;
  228.     SetCursor(watchHdl^^);
  229. END.  {main}